import request from "./request";

/**
 * 登录
 * @param data 请求参数
 * @returns
 */
export const loginPost = (data: LoginBody) => {
  return new Promise<UserInfo>(async (resolve, reject) => {
    const res: AxiosResData<UserInfo> = await request.post(
      "/acc/doLogin",
      data
    );
    resolve(res.data.result);
  });
};
/**
 * 退出登录
 * @returns
 */
export const logout = () => {
  return new Promise(async (resolve, reject) => {
    await request.get("/acc/logout");
    resolve(true);
  });
};
/**
 * 当前用户信息
 * @returns
 */
export const getUserInfo = () => {
  return new Promise<UserInfo>(async (resolve, reject) => {
    const res: AxiosResData<UserInfo> = await request.get("/acc/getSubject");
    resolve(res.data?.result || {});
  });
};

/**
 * 当前菜单信息
 * @returns
 */
export const getMenus = () => {
  return new Promise<SysMenuType[]>(async (resolve, reject) => {
    const res: AxiosResData<SysMenuType[]> = await request.get("/acc/menus");
    resolve(res.data?.result || []);
  });
};

/**
 * 获取字典数据
 * @param data string[]
 * @returns 
 */
export const getDictList = (data:Array<String>) => {
  return new Promise<DictInfoType>(async (resolve, reject) => {
    const res: AxiosResData<DictInfoType> = await request.post("/sysDictData/getDictInfo",data);
    resolve(res.data?.result || []);
  }); 
}